<template>
  <div class="GospelSelect" :style="{width:width}">
    <span class="s-remark" v-if="link_type.params_type==0">不需要参数</span>
    <a-input v-if="link_type.params_type==1" :placeholder="'请输入要打开的'+link_type.name" type="text" :size="size" v-model="inputValue"></a-input>
    <j-upload v-if="link_type.params_type==1&&link_type.id==27" v-model="inputValue" :number="1"></j-upload>
    <a-input-search v-if="link_type.params_type==2" :placeholder="'请选择要打开的'+link_type.name" enter-button v-model="inputValue"
      @search="openNetMiDialog(link_type.id)" :size="size" />

    <gms-good-ref ref="modalGoods" @ok="modalGoodsOk" />
    <sms-shop-ref ref="modalShops" @ok="modalShopsOk" />
    <cms-floor-content-ref ref="modalRichs" @ok="modalRichsOk" />
    <cms-floor-position-ref ref="modalFloors" @ok="modalFloorsOk" />
    <gms-category-ref ref="modalClass" @ok="modalClassOk" />
    <sms-category-ref ref="modalClassIndex" @ok="modalClassIndexOk" />
    <mms-coupon-ref ref="modalConpon" @ok="modalConponOk" />
    <lbms-good-ref ref="modalLbGoods" @ok="modalLbGoodsOk" />

  </div>
</template>

<script>
import { postAction } from '@/api/manage'
import GmsGoodRef from '@/views/gospel/mallBase/good/modules/GmsGoodRef'
import SmsShopRef from '@/views/gospel/mallBase/shop/modules/SmsShopRef'
import CmsFloorContentRef from '@/views/gospel/common/floor/modules/CmsFloorContentRef'
import CmsFloorPositionRef from '@/views/gospel/common/floor/modules/CmsFloorPositionRef'
import SmsCategoryRef from '@/views/gospel/mallBase/shop/modules/SmsCategoryRef'
import GmsCategoryRef from '@/views/gospel/mallBase/good/modules/GmsCategoryRef'
import MmsCouponRef from '@/views/gospel/mallPlus/coupon/modules/MmsCouponRef'
import LbmsGoodRef from '@/views/gospel/mallPlus/lb/modules/LbmsGoodRef'
import JUpload from '@/components/jeecg/JUpload'



export default {
  name: 'GospelSelect',
  components: {
    GmsGoodRef,
    SmsShopRef,
    CmsFloorContentRef,
    CmsFloorPositionRef,
    SmsCategoryRef,
    GmsCategoryRef,
    MmsCouponRef,
    LbmsGoodRef,
    JUpload
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    width: {
      type: String,
      default: '100%'
    },
    size: {
      type: String,
      default: 'small'
    },
    link_type: {
      type: Object,
      default: function () {
        return {
          id: 0,
          name: '点击无效果'
        }
      }
    }
  },
  data () {
    return {
      inputValue: this.value
    }
  },
  watch: {
    value: {
      deep: true,  // 深度监听
      handler (newVal, oldVal) {
        this.inputValue = newVal
      }
    },
    inputValue (val) {
      this.$emit('input', val)
    }
  },
  methods: {
    openNetMiDialog (type) {
      if (type == 1) {
        this.$refs.modalGoods.visible = true
        this.$refs.modalGoods.refStatus = 1;
        console.log("你好");
        this.$refs.modalGoods.open()
      } else if (type == 2) {
        this.$refs.modalShops.visible = true
        this.$refs.modalShops.open("A00001A00001")
      } else if (type == 6) {
        this.$refs.modalRichs.visible = true
        this.$refs.modalRichs.open()
      } else if (type == 13) {
        this.$refs.modalClass.visible = true
        this.$refs.modalClass.open()
      } else if (type == 15) {
        this.$refs.modalLbGoods.visible = true
        this.$refs.modalLbGoods.open()
      } else if (type == 8) {
        this.$refs.modalFloors.visible = true
        this.$refs.modalFloors.open()
      } else if (type == 29) {
        this.$refs.modalConpon.visible = true
        this.$refs.modalConpon.open()
      } else if (type == 31) {
        this.$refs.modalClassIndex.visible = true
        this.$refs.modalClassIndex.open()
      }

    },
    modalGoodsOk (row) {
      if (this.link_type.id == 99) {
        this.inputValue = row.id
      } else {
        this.inputValue = row.itemCode
      }
      this.$emit('change', row)
    },
    modalLbGoodsOk (row) {
      this.inputValue = row.itemCode
      this.$emit('change', row)
    },
    modalShopsOk (row) {
      this.inputValue = row.id
      this.$emit('change', row)
    },
    modalRichsOk (row) {
      this.inputValue = row.id
      this.$emit('change', row)
    },
    modalFloorsOk (row) {
      this.inputValue = row.positionCode
      this.$emit('change', row)
    },
    modalClassOk (row) {
      this.inputValue = row.id
      this.$emit('change', row)
    },
    modalClassIndexOk (row) {
      if (row.pid) {
        this.inputValue = row.pid + "," + row.id
        this.$emit('change', row)
      } else {
        this.inputValue = row.id
        this.$emit('change', row)
      }

    },
    modalConponOk (row) {
      this.inputValue = row.id
      this.$emit('change', row)
    },
  }
}
</script>

<style lang="less" scoped>
.GospelSelect {
  width: 100%;
  .s-remark {
    color: #999999;
    font-size: 13px;
  }
}
</style>
